To be able to edit code and run cells, you need to run the notebook yourself. Where would you like to run the notebook?

This notebook takes about 3 minutes to run.

In the cloud (experimental)

Binder is a free, open source service that runs scientific notebooks in the cloud! It will take a while, usually 2-7 minutes to get a session.

On your computer

(Recommended if you want to store your changes.)

  1. Copy the notebook URL:
  2. Run Pluto

    (Also see: How to install Julia and Pluto)

  3. Paste URL in the Open box

Frontmatter

If you are publishing this notebook on the web, you can set the parameters below to provide HTML metadata. This is useful for search engines and social media.

Author 1
👀 Reading hidden code
using JuMP, Ipopt
62.7 s
setup_opt_model (generic function with 1 method)
👀 Reading hidden code
setup_opt_model() = Model(optimizer_with_attributes(Ipopt.Optimizer,
"acceptable_tol" => 1.e-8, "max_iter" => Int64(1e8),
"acceptable_constr_viol_tol" => 1.e-3, "constr_viol_tol" => 1.e-4,
"print_frequency_iter" => 50, "print_timing_statistics" => "no",
"print_level" => 0,
))
576 μs
halfsum (generic function with 1 method)
👀 Reading hidden code
function halfsum(xs::Vector{<:Real})
sum((xs .- 0.5).^2) + .001 * (sum(xs) - 50)^2
end
776 μs
halfsum_jump (generic function with 1 method)
👀 Reading hidden code
function halfsum_jump(xs...)
halfsum(collect(xs))
end
406 μs
cumsum_jump (generic function with 1 method)
👀 Reading hidden code
function cumsum_jump(xsi...)
xs = collect(xsi[1:N])
cumsum(collect(xs))
end
515 μs
200
👀 Reading hidden code
N = 200
10.5 μs
👀 Reading hidden code
begin
model_optimizer = setup_opt_model()
local m = model_optimizer
M = @variable(model_optimizer, 0.0 <= M[1:N] <= 1.0)

# Register our wrapper functions
###
register(m,
:halfsum_jump,
N,
autodiff=true
)
# Objective
###
min_objective = @NLobjective(
m, Min,
)
for i in 1:N
@NLconstraint(m,
M[i] >= i / N
)
end
4.2 s
A JuMP Model
├ solver: Ipopt
├ objective_sense: MIN_SENSE
│ └ objective_function_type: AffExpr
├ num_variables: 200
├ num_constraints: 600
│ ├ JuMP.VariableRef in MOI.GreaterThan{Float64}: 200
│ ├ JuMP.VariableRef in MOI.LessThan{Float64}: 200
│ └ Nonlinear: 200
└ Names registered in the model
  └ :M
model_optimized = let
optimize!(model_optimizer)
model_optimizer
end
👀 Reading hidden code
❔
******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit https://github.com/coin-or/Ipopt
******************************************************************************

9.2 s
LOCALLY_SOLVED::TerminationStatusCode = 4
termination_status(model_optimized)
👀 Reading hidden code
18.9 ms
value.(M)
👀 Reading hidden code
140 ms
begin
model_optimizer2 = setup_opt_model()
local m = model_optimizer2
M2 = @variable(m, 0.0 <= M2[1:N] <= 1.0)
# Objective
###
for i in 1:N
@NLconstraint(m,
M2[i] >= i / N
)
end
min_objective2 = @NLobjective(
m, Min,
# sum(
# (M2[i] - 0.5) ^ 2
# for i in 1:N
# )
sum(
(M2[i] - 0.5)^2
for i in 1:N) + .001 * (sum(M2[i] for i in 1:N) - 50)^2
)
min_objective2
end;
👀 Reading hidden code
2.4 s
A JuMP Model
├ solver: Ipopt
├ objective_sense: MIN_SENSE
│ └ objective_function_type: AffExpr
├ num_variables: 200
├ num_constraints: 600
│ ├ JuMP.VariableRef in MOI.GreaterThan{Float64}: 200
│ ├ JuMP.VariableRef in MOI.LessThan{Float64}: 200
│ └ Nonlinear: 200
└ Names registered in the model
  └ :M2
model_optimized2 = let
optimize!(model_optimizer2)
model_optimizer2
end
👀 Reading hidden code
5.4 s
value.(M2)
👀 Reading hidden code
200 μs